package com.campuscarbooking.api.dto;

import com.campuscarbooking.api.model.Reservation;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ReservationDTO {
    private Long id;
    private Long userId;
    private Long scheduleId;
    private BusScheduleDTO schedule;
    private String seatNumber;
    private String status;
    private String paymentStatus;
    private String paymentMethod;
    private BigDecimal amountPaid;
    private LocalDateTime reservationTime;
    private LocalDateTime canceledAt;
    private Boolean signedIn;
    private LocalDateTime signInTime;
    private LocalDateTime createdAt;

    public static ReservationDTO fromEntity(Reservation reservation, BusScheduleDTO schedule) {
        if (reservation == null) {
            return null;
        }

        ReservationDTO dto = new ReservationDTO();
        dto.setId(reservation.getId());
        if (reservation.getUser() != null) {
            dto.setUserId(reservation.getUser().getId());
        }
        if (reservation.getSchedule() != null) {
            dto.setScheduleId(reservation.getSchedule().getId());
        }
        dto.setSchedule(schedule);
        dto.setSeatNumber(reservation.getSeatNumber());
        dto.setStatus(reservation.getStatus().name());
        dto.setPaymentStatus(reservation.getPaymentStatus().name());
        if (reservation.getPaymentMethod() != null) {
            dto.setPaymentMethod(reservation.getPaymentMethod().name());
        }
        dto.setAmountPaid(reservation.getAmountPaid());
        dto.setReservationTime(reservation.getReservationTime());
        dto.setCanceledAt(reservation.getCanceledAt());
        dto.setSignedIn(reservation.getSignedIn());
        dto.setSignInTime(reservation.getSignInTime());
        dto.setCreatedAt(reservation.getCreatedAt());

        return dto;
    }

    public static ReservationDTO fromEntity(Reservation reservation) {
        return fromEntity(reservation, null);
    }
} 